package com.sc.servlet.admin.field;

import com.alibaba.fastjson.JSONObject;
import com.sc.pojo.Field;
import com.sc.services.FieldServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @description: 更新场地信息
 * @author: sc
 * @create: 2023-01-03 20:18
 **/
@WebServlet("/updateField")
public class updateFieldServlet extends HttpServlet {

    private FieldServices fieldServices = new FieldServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader reader = request.getReader();
        String readLine = reader.readLine();
        JSONObject jsonObject = JSONObject.parseObject(readLine);
        String res=null;


        Field updatefield = new Field();

        updatefield.setFieldincharge(jsonObject.getString("fieldincharge"));
        updatefield.setFieldinformation(jsonObject.getString("fieldinformation"));
        updatefield.setFieldpicture(jsonObject.getString("fieldpicture"));
        updatefield.setFieldlocation(jsonObject.getString("fieldlocation"));
        updatefield.setFieldstate(jsonObject.getString("fieldstate"));
        updatefield.setFieldname(jsonObject.getString("fieldname"));
        updatefield.setFieldid(Integer.parseInt(jsonObject.getString("fieldid")));
        updatefield.setShowstate(Integer.parseInt(jsonObject.getString("showstate")));
        System.out.println(updatefield);
        try {
            fieldServices.updateField(updatefield);
            res ="update_suc";
        }catch (Exception e){
            res = "wrong_adminname";
        }
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(res);



    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}